package ar.com.spsolutions.splibrary.book;

import ar.com.spsolutions.splibrary.entity.Entity;

public class StarsCounter extends Entity implements StarAble {
	private static final long serialVersionUID = -2146123161333347491L;

	private static final int ONE_STAR = 1;

	private static final int TWO_STAR = 2;

	private static final int THREE_STAR = 3;

	private static final int FOUR_STAR = 4;

	private static final int FIVE_STAR = 5;

	private Integer votes = 0;

	private Integer currentStar = 0;

	private void addStars(final int amount) {
		this.setVotes(this.getVotes() + 1);
		this.setCurrentStar(this.getCurrentStar() + amount);
	}

	@Override
	public void addOneStar() {
		this.addStars(StarsCounter.ONE_STAR);
	}

	@Override
	public void addTwoStar() {
		this.addStars(StarsCounter.TWO_STAR);
	}

	@Override
	public void addThreeStar() {
		this.addStars(StarsCounter.THREE_STAR);
	}

	@Override
	public void addFourStar() {
		this.addStars(StarsCounter.FOUR_STAR);
	}

	@Override
	public void addFiveStar() {
		this.addStars(StarsCounter.FIVE_STAR);
	}

	@Override
	public Integer getStars() {
		return this.getVotes() > 0 ? this.getCurrentStar() / this.getVotes()
				: 0;
	}

	@Override
	public Integer getVotes() {
		return this.votes;
	}

	public void setVotes(final Integer votes) {
		this.votes = votes;
	}

	public Integer getCurrentStar() {
		return this.currentStar;
	}

	public void setCurrentStar(final Integer currentStar) {
		this.currentStar = currentStar;
	}

	@Override
	public String toString() {
		return this.getStars().toString();
	}

	@Override
	public void setStars(final Integer stars) {
		this.setCurrentStar(stars);
		this.setVotes(1);
	}

}
